package com.ruoyi.client.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.supply.domain.LocationInfo;
import com.ruoyi.supply.enums.SupplyInfoStatusEnum;
import com.ruoyi.supply.service.impl.LocationInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地点资讯Controller
 * 
 * @author Ryan
 * @date 2025-06-07
 */
@RestController
@RequestMapping("/client/info/location")
@Api(tags = "客户端 地点资讯")
public class ClientLocationInfoController extends BaseController
{
    @Autowired
    private LocationInfoService locationInfoService;


    /**
     * 购买货源/地点的联系方式
     */
    @GetMapping("/contact/{id}")
    @ApiOperation("获取地点联系方式")
    public AjaxResult getLocationContact(@PathVariable("id") Long id){
        String phone = locationInfoService.clintGetContact(id);
        return AjaxResult.success("success",phone);
    }

    /**
     * 查询地点资讯列表
     */
    @GetMapping("/list")
    @ApiOperation("查询地点资讯")
    public TableDataInfo list(LocationInfo locationInfo)
    {
        startPage();
        locationInfo.setStatus(SupplyInfoStatusEnum.AUDIT_PASS.getCode());
        List<LocationInfo> list = locationInfoService.selectInfoList(locationInfo);
        if(CollUtil.isNotEmpty(list)){
            list.forEach(it->{
                it.setPhone(null);
            });
        }
        return getDataTable(list);
    }


    /**
     * 获取地点资讯详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取地点资讯详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        LocationInfo locationInfo = locationInfoService.selectInfoById(id);
        locationInfo.setPhone(null);
        return success(locationInfo);
    }

    /**
     * 新增地点资讯
     */
    @Log(title = "地点资讯", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增地点资讯")
    public AjaxResult add(@RequestBody LocationInfo locationInfo)
    {
        locationInfo.setStatus(SupplyInfoStatusEnum.WAIT_AUDIT.getCode());
        return toAjax(locationInfoService.insertInfo(locationInfo));
    }

    /**
     * 修改地点资讯
     */
    @Log(title = "地点资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改地点资讯")
    public AjaxResult edit(@RequestBody LocationInfo locationInfo)
    {
        return toAjax(locationInfoService.updateInfo(locationInfo));
    }

    /**
     * 删除地点资讯
     */
    @Log(title = "地点资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    @ApiOperation("删除地点资讯")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(locationInfoService.deleteInfoById(id));
    }


}
